#ifndef BEE_API_H__
#define BEE_API_H__


#include "user_extern.h" 

#include "esp_log.h"
#include "esp_system.h"
#include "esp_err.h"

#include "esp8266/gpio_register.h"
#include "esp8266/pin_mux_register.h"

#include "driver/pwm.h"



// 定义低音音名（数值单位：Hz）
#define L0 50005
#define L1 262 // c
#define L2 294 // d
#define L3 330 // e
#define L4 349 // f
#define L5 392 // g
#define L6 440 // a1
#define L7 494 // b1

// 定义中音音名
#define M1 523 // c1
#define M2 587 // d1
#define M3 659 // e1
#define M4 698 // f1
#define M5 784 // g1
#define M6 880 // a2
#define M7 988 // b2

// 定义高音音名
#define H1 1047 // c2
#define H2 1175 // d2
#define H3 1319 // e2
#define H4 1397 // f2
#define H5 1568 // g2
#define H6 1760 // a3
#define H7 1976 // b3

// 定义高音音名
#define HH1 2094 // c3
#define HH2 2350 // c3
#define HH3 2638 // e3
#define HH4 2794 // f3
#define HH5 3136 // g3
#define HH6 3520 // a3
#define HH7 3952 // b3

#define H51 3136    //C5
#define H52 2794/2  //D5


// 定义时值单位，决定演奏速度（数值单位：ms）
#define _T 2000
#define TT 2000

//定义音符结构
typedef struct
{
    short mName; // 音名：取值L1～L7、M1～M7、H1～H7分别表示低音、中音、高音的1234567，取值0表示休止符
    short mTime; // 时值：取值T、T/2、T/4、T/8、T/16、T/32分别表示全音符、 二分音符、四分音符、八分音符 ，取值0表示演奏结束
} tNote;

typedef struct _tone{
    uint8_t press;
    void (*button_tone)(void);
    void (*alarm_tone)(void);
    void (*music_play)(void);
    void (*on)(void);
    void (*quiet)(void);
}Tone;
extern Tone tone;
void bee_init(void);


#if 0
const tNote MyScore[] =
    {
#if 1
        {H51, T / 16},
        {H52, T / 16},
        {H51, T / 16},
        {H52, T / 16},
        {H51, T / 16},
        {H52, T / 16},
        {L0, T / 8},
        {L0, T / 8},
        {L0, T / 8},
        {H51, T / 16},
        {H52, T / 16},
        {H51, T / 16},
        {H52, T / 16},
        {H51, T / 16},
        {H52, T / 16},
        {H51, T / 16},
        {H52, T / 16},
#else

        {M3, T / 8}, {M3, T / 8}, {M5, T / 8}, {M5, T / 8}, {M5, T / 8}, {M5, T / 8}, {M3, T / 8}, {M3, T / 8}, {M6, T / 8 + T / 8}, {M5, T / 8 + T / 16}, {L0, T / 8}, {M3, T / 8}, {M3, T / 8}, {M3, T / 8}, {M5, T / 8}, {M5, T / 8}, {M5, T / 8}, {M5, T / 8}, {M3, T / 8}, {M3, T / 8}, {M6, T / 8 + T / 8}, {M7, T / 4}, {L0, T / 4},

        {M3, T / 8},
        {M2, T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M1, T / 8},
        {L0, T / 8},
        {L0, T / 4},
        {M1, T / 8},
        {M1, T / 8},
        {M3, T / 8 + T / 8},
        {M2, T / 8},
        {M1, T / 8},
        {M4, T / 8},
        {M4, T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M1, T / 8 + T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},

        {M3, T / 8 + T / 8},
        {M5, T / 8},
        {M5, T / 8},
        {M5, T / 8},
        {M5, T / 8},
        {M3, T / 8},
        {M6, T / 8},
        {M6, T / 8},
        {M5, T / 8},
        {L0, T / 4},
        {L0, T / 4},
        {M3, T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {M5, T / 8},
        {M5, T / 8},
        {M5, T / 8},
        {M5, T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {M6, T / 8 + T / 8},
        {M7, T / 4 + T / 16},
        {L0, T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M1, T / 4 + T / 16},
        {L0, T / 8},
        {M1, T / 8},
        {M1, T / 8},
        {M3, T / 8 + T / 8},
        {M2, T / 8},
        {M1, T / 8},
        {M4, T / 8 + T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M1, T / 8 + T / 8},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},

        {L0, T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {H1, T / 4},
        {M7, T / 4},
        {M6, T / 8},
        {M5, T / 4},
        {M3, T / 8 + T / 4},
        {L0, T / 4},
        {L0, T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M3, T / 8},
        {M2, T / 8},
        {M1, T / 8},
        {M1, T / 8},
        {L6, T / 8},
        {M1, T / 8},
        {M2, T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {M4, T / 8},
        {M3, T / 8 + T / 16},
        {L0, T / 4},

        {M3, T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {H1, T / 4},
        {M7, T / 4},
        {M6, T / 8},
        {M5, T / 4},
        {M3, T / 8 + T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {M3, T / 4},
        {M3, T / 4},
        {M4, T / 8},
        {M3, T / 8},
        {M4, T / 8},
        {M5, T / 8 + T / 8},
        {M4, T / 8},
        {M5, T / 8},
        {M6, T / 8 + T / 8},
        {M5, T / 8},
        {M6, T / 8},
        {M7, T / 8},
        {M7, T / 4 + T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},

        {L0, T / 8},
        {M5, T / 8},
        {H1, T / 4 + T / 8},
        {H2, T / 8 + T / 4},
        {H3, T / 4},
        {H2, T / 4},
        {H3, T / 8},
        {H2, T / 8 + T / 8},
        {H1, T / 8},
        {M7, T / 8},
        {H1, T / 8 + T / 8},
        {L0, T / 8},
        {L0, T / 8},
        {M6, T / 8},
        {H1, T / 8},
        {H3, T / 8},
        {H2, T / 8},
        {H2, T / 8},
        {H1, T / 8},
        {H1, T / 8},
        {H1, T / 8},
        {H2, T / 8},
        {H1, T / 8 + T / 4},
        {H1, T / 8 + T / 8},
        {M7, T / 8},
        {M6, T / 8},
        {M5, T / 8 + T / 8},
        {M3, T / 8},
        {M3, T / 8},
        {M6, T / 8 + T / 4},
        {L0, T / 8},
        {M6, T / 8},
        {H1, T / 8},
        {M6, T / 8},
        {H1, T / 8},
        {M6, T / 8},
        {H1, T / 8},
        {M6, T / 8},
        {M6, T / 8},
        {H3, T / 8 + T / 8},
        {H3, T / 8},
        {H2, T / 4},
        {H1, T / 8},
        {H2, T / 4 + T / 8},
        {H1, T / 4 + T / 8},
        {H2, T / 8},
        {H2, T / 4},
        {H3, T / 4},
        {H2, T / 4},
        {H2, T / 8},
        {H2, T / 8 + T / 8},
        {H1, T / 8},
        {M7, T / 8},
        {H1, T / 8 + T / 4 + T / 4},
        {L0, T / 4},

        {M6, T / 8},
        {H1, T / 8},
        {H3, T / 8},
        {H2, T / 8},
        {H2, T / 8},
        {H2, T / 8},
        {H5, T / 8},
        {M7, T / 8},
        {M7, T / 8},
        {H1, T / 8 + T / 8},
        {L0, T / 8},
        {H1, T / 8 + T / 8},
        {M7, T / 8},
        {M6, T / 8},
        {M5, T / 8 + T / 8},
        {M5, T / 8},
        {H2, T / 8},
        {H1, T / 8 + T / 4 + T / 4},
        {H1, T},
        {M7, T},
        {H1, T},
        {H1, T / 4 + T / 4 + T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {L0, T / 4},
        {0, 0}
#endif
};
#endif
#endif
